package com.feicheng.lanniao.service.impl.payRecord;

import com.feicheng.lanniao.entity.PayRecord;
import com.feicheng.lanniao.exception.SystemException;
import com.feicheng.lanniao.mapper.payRecord.PayRecordMapper;
import com.feicheng.lanniao.service.payRecord.PayRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class PayRecordServiceImpl implements PayRecordService {

    @Autowired
    private PayRecordMapper payRecordMapper;

    /**
     * @param clientId  用户Id
     * @desctiption 查询这个用户的最新一条支付记录
     * @return  这个用户的最新支付记录
     */
    @Override
    public PayRecord selectLatestPayRecordCountByClientId(Integer clientId) {
        log.info("PayRecordServiceImpl的PayRecordService方法进入,参数clientId为"+clientId);
        PayRecord payRecord = payRecordMapper.selectLatestPayRecordCountByClientId(clientId);
        return payRecord;
    }


    /**
     * @param Id 根据主键
     * @descriptino 根据主键Id更新次数+1
     * @return 更新条数
     */
    @Override
    public void updateTimesOfLatestPayRecordById(Integer Id) {
        log.info("PayRecordServiceImpl的updateTimesOfLatestPayRecordById方法进入,Id"+Id);
        Integer updateCount = payRecordMapper.updateTimesOfLatestPayRecordById(Id);
        if(updateCount != 1){
            throw new SystemException("更新可查询次数失败");
        }
    }
}
